home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / irix / tools / Lastrev.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  41.0 KB  |  1,916 lines

  1. /*----------------------------------------------------------------------
  2.  * $Id: Lastrev.c++,v 1.7 1993/11/30 15:16:29 carlson Exp $
  3.  *
  4.  * This program collects information about the revisions and symbols
  5.  * defined in RCS files and then prints this information.
  6.  *
  7.  * Revision History:
  8.  *    $Log: Lastrev.c++,v $
  9. // Revision 1.7  1993/11/30  15:16:29  carlson
  10. // Modified so that it will compile on 4.0.5 (added include file for getopt.h).
  11. // Fixed a bug where it won't see the end of a comment line if comment
  12. //   contains a semicolon.
  13. // Use the macro S_ISDIR instead of testing the flag.
  14. // If the file being tested is a directory, skip it.
  15. //
  16. // Revision 1.3.1.1  93/11/29  18:37:44  carlson
  17. // test file
  18. // 
  19. // Revision 1.6  93/11/19  00:13:27  carlson
  20. // Needed to intialize all the elements of every class to something.
  21. // Changed all '\n' in print statements to use endl.
  22. // Fixed a couple of places where I didn't reset a pointer to the very
  23. //   beginning (since it was automatically incremented in a loop).
  24. // Changed the way branches were scanned and added.  The old way didn't
  25. //   allow for multiple branches to be specified in one 'branch' statement
  26. //   but the new way does.
  27. // Found a place where an error message didn't end with endl;
  28. // 
  29. // Revision 1.5  1993/11/18  21:34:54  carlson
  30. // Fixed a bug where it never inserted symbols or deltas after the first.
  31. // Moved the printing of the titles to a different place.
  32. //
  33. // Revision 1.4  1993/06/22  00:03:36  chris
  34. // Completed this program.  Only thing left to do is allow user to specify
  35. //   a directory and not each file.
  36. //
  37. // Revision 1.3  1993/06/14  05:44:03  chris
  38. // Put most of work into subroutine.
  39. //
  40. // Revision 1.2  1993/06/14  04:33:27  chris
  41. // Made numberous improvements.  Still not finished.
  42. //
  43.  *
  44.  * Wed May 26 15:29:42 1993
  45.  * Rewritten from scratch because I can't find the original sources.
  46.  *----------------------------------------------------------------------*/
  47.  
  48. #include <stdio.h>
  49. #include <errno.h>
  50. #include <ctype.h>
  51. #include <string.h>
  52. #include <iostream.h>
  53. #include <fstream.h>
  54. #include <stdlib.h>
  55. #include <memory.h>
  56. #include <sys/types.h>
  57. #include <sys/stat.h>
  58. #ifdef __SVR3
  59. #include <getopt.h>
  60. #endif
  61.  
  62. // #define DEBUG
  63. // #define DEBUG1
  64.  
  65. #define ARRAY_SIZE    10
  66. #define MAX_BRANCHES    10
  67.  
  68. #define SKIP_SPACE(c)    while (*c && isspace (*c)) c++
  69. #define TAB_OUT(c,to)    (c) = (c) - ((c) % 8); \
  70.             while ((c) < (to)) { cout << '\t'; c += 8; }
  71.  
  72. #define False        0
  73. #define True        1
  74.  
  75. /*========================================================================
  76.  * Revision class
  77.  *========================================================================*/
  78.  
  79. typedef enum {SAME = 0, HIGHER, LOWER, MORE_LEVELS, LESS_LEVELS,
  80.           DIFFERENT, DIFFERENT_BRANCH, ERROR} dType;
  81.  
  82. class Revision
  83. {
  84.   private:
  85.     short    number[ARRAY_SIZE];
  86.     char    *author;
  87.     char    *state;
  88.     Revision    *branches[MAX_BRANCHES];
  89.     Revision    *nextRev;
  90.  
  91.     void    convertToArray (char *rev, short *array);
  92.     char    *convertToString (short *array);
  93.  
  94.   public:
  95.     Revision (char *c = NULL);
  96.     Revision (Revision &r);
  97.     ~Revision ();
  98.     Revision& operator= (char *r);
  99.     Revision& operator= (Revision &r);
  100.  
  101.     void    SetRevision (char *r);
  102.     void    SetAuthor (char *s);
  103.     void    SetState (char *s);
  104.     void    AddBranch (Revision *r);
  105.     void    SetNext (Revision *r);
  106.  
  107.     dType    CompareRevs (Revision &r);
  108.     Revision    *ConditionalSetRevision (Revision *rev, Revision *base);
  109.  
  110.     char    *GetRevision (void);
  111.     char    *GetState (void) { return state; }
  112.     Revision    *GetNext (void) { return nextRev; }
  113.     void    printRev (char *indent);
  114.     virtual void    printAll (char *indent);
  115. };
  116.  
  117. /*------------------------------------------------------------------------
  118.  * Revision::Revision
  119.  *------------------------------------------------------------------------*/
  120.  
  121. Revision::Revision (char *c)
  122. {
  123.     number[0] = -1;
  124.     if (c)
  125.     convertToArray (c, number);
  126.     author = NULL;
  127.     state = NULL;
  128.     branches[0] = NULL;
  129.     nextRev = NULL;
  130. }
  131.  
  132. /*------------------------------------------------------------------------
  133.  * Revision::Revision
  134.  *------------------------------------------------------------------------*/
  135.  
  136. Revision::Revision (Revision &r)
  137. {
  138.     memcpy (number, r.number, sizeof (number));
  139.     state = new char [strlen (r.state) + 1];
  140.     strcpy (state, r.state);
  141.     author = new char [strlen (r.author) + 1];
  142.     strcpy (author, r.author);
  143.     memcpy (branches, r.branches, sizeof (branches));
  144.     nextRev = r.nextRev;
  145. }
  146.  
  147. /*------------------------------------------------------------------------
  148.  * Revision::~Revision
  149.  *------------------------------------------------------------------------*/
  150.  
  151. Revision::~Revision ()
  152. {
  153.     delete [] state;
  154. }
  155.  
  156. /*------------------------------------------------------------------------
  157.  * Revision::operator=
  158.  *------------------------------------------------------------------------*/
  159.  
  160. Revision& Revision::operator= (char *r)
  161. {
  162.     convertToArray (r, number);
  163.     if (state)
  164.     delete [] state;
  165.     state = NULL;
  166.     branches[0] = NULL;
  167.     nextRev = NULL;
  168.  
  169.     return *this;
  170. }
  171.  
  172. /*------------------------------------------------------------------------
  173.  * Revision::operator=
  174.  *------------------------------------------------------------------------*/
  175.  
  176. Revision& Revision::operator= (Revision &r)
  177. {
  178.     memcpy (number, r.number, sizeof (number));
  179.     if (state)
  180.     delete [] state;
  181.     state = new char [sizeof (r.state) + 1];
  182.     strcpy (state, r.state);
  183.     memcpy (branches, r.branches, sizeof (branches));
  184.     nextRev = r.nextRev;
  185.  
  186.     return *this;
  187. }
  188.  
  189. /*------------------------------------------------------------------------
  190.  * Revision::SetRevision
  191.  *------------------------------------------------------------------------*/
  192.  
  193. void Revision::SetRevision (char *r)
  194. {
  195.     convertToArray (r, number);
  196. }
  197.  
  198. /*------------------------------------------------------------------------
  199.  * Revision::SetAuthor
  200.  *------------------------------------------------------------------------*/
  201.  
  202. void Revision::SetAuthor (char *s)
  203. {
  204.     if (author)
  205.     delete [] author;
  206.     author = new char [strlen (s) + 1];
  207.     strcpy (author, s);
  208. }
  209.  
  210. /*------------------------------------------------------------------------
  211.  * Revision::SetState
  212.  *------------------------------------------------------------------------*/
  213.  
  214. void Revision::SetState (char *s)
  215. {
  216.     if (state)
  217.     delete [] state;
  218.     state = new char [strlen (s) + 1];
  219.     strcpy (state, s);
  220. }
  221.  
  222. /*------------------------------------------------------------------------
  223.  * Revision::AddBranch
  224.  *------------------------------------------------------------------------*/
  225.  
  226. void Revision::AddBranch (Revision *r)
  227. {
  228.     int i;
  229.     for (i = 0; i < MAX_BRANCHES; i++)
  230.     {
  231.     if (branches[i] == NULL)
  232.     {
  233.         branches[i] = r;
  234.         if (i < (MAX_BRANCHES - 1))
  235.         branches[i+1] = NULL;
  236.         break;
  237.     }
  238.     }
  239. }
  240.  
  241. /*------------------------------------------------------------------------
  242.  * Revision::SetNext
  243.  *------------------------------------------------------------------------*/
  244.  
  245. void Revision::SetNext (Revision *r)
  246. {
  247.     nextRev = r;
  248. }
  249.  
  250. /*------------------------------------------------------------------------
  251.  * Revision::GetRevision
  252.  *------------------------------------------------------------------------*/
  253.  
  254. char *Revision::GetRevision (void)
  255. {
  256.     return convertToString (number);
  257. }
  258.  
  259. /*------------------------------------------------------------------------
  260.  * Revision::convertToArray
  261.  *------------------------------------------------------------------------*/
  262.  
  263. void Revision::convertToArray (char *rev, short *array)
  264. {
  265.     int            i;
  266.     char        *tmp, *ptr, *pptr;
  267.  
  268.     tmp = new char [strlen (rev) + 1];
  269.     strcpy (tmp, rev);
  270.  
  271.     for (pptr = ptr = tmp, i = 0; *pptr; )
  272.     {
  273.     while (isdigit (*ptr))
  274.         ptr++;
  275.     if (*ptr == '.')
  276.     {
  277.         *ptr = '\0';
  278.         array[i++] = atoi (pptr);
  279.         pptr = ++ptr;
  280.     }
  281.     else if (*ptr == '\0')
  282.     {
  283.         array[i++] = atoi (pptr);
  284.         pptr = ptr;
  285.     }
  286.     else
  287.     {
  288.         cerr << "Revision::convertToArray: Illegal revision number - "
  289.          << rev << endl;
  290.     }
  291.     }
  292.  
  293.     array[i] = -1;
  294.     delete [] tmp;
  295. }
  296.  
  297. /*------------------------------------------------------------------------
  298.  * Revision::convertToString
  299.  *------------------------------------------------------------------------*/
  300.  
  301. char *Revision::convertToString (short *array)
  302. {
  303.     static char        retval[50], *rv;
  304.     int            i;
  305.  
  306.     for (i = 0, rv = retval; i < ARRAY_SIZE; i++)
  307.     {
  308.     if (array[i] == -1)
  309.         break;
  310.  
  311.     if (rv != retval)
  312.         *rv++ = '.';
  313.     sprintf (rv, "%d", array[i]);
  314.     rv = rv + strlen (rv);
  315.     }
  316.  
  317.     return retval;
  318. }
  319.  
  320. /*------------------------------------------------------------------------
  321.  * Revision::CompareRevs
  322.  *
  323.  * This routine compares the revision numbers of two Revisions.  It
  324.  * assumes that \'this\' is set to the base revision and the passed
  325.  * in revision is to find out if this revision should replace it.
  326.  *------------------------------------------------------------------------*/
  327.  
  328. dType Revision::CompareRevs (Revision &r)
  329. {
  330.     int        i;
  331.     dType    retval = ERROR;
  332.  
  333.     for (i = 0; i < ARRAY_SIZE; i++)
  334.     {
  335.     if (number[i] == -1)
  336.     {
  337.         if (r.number[i] == -1)
  338.         retval = SAME;        // The two revisions are the same
  339.         else if ((i % 2) != 0)
  340.         retval = MORE_LEVELS;    // r has more levels but same base
  341.         else
  342.         retval = DIFFERENT_BRANCH; // r is a different branch
  343.         break;
  344.     }
  345.     else if (r.number[i] == -1)
  346.     {
  347.         retval = LESS_LEVELS;    // r has less levels
  348.         break;
  349.     }
  350.     else if (number[i] < r.number[i])
  351.     {
  352.         retval = HIGHER;        // r is a higher level
  353.         break;
  354.     }
  355.     else if (number[i] > r.number[i])
  356.     {
  357.         retval = LOWER;        // r is a lower level
  358.         break;
  359.     }
  360.     }
  361.  
  362.     return retval;
  363. }
  364.  
  365. /*------------------------------------------------------------------------
  366.  * Revision::ConditionalSetRevision
  367.  *
  368.  * Used to set the actual revision when comparing to a base revision.
  369.  * Usage:
  370.  *    actual = actual->ConditionalSetRevision (toTest, base);
  371.  *------------------------------------------------------------------------*/
  372.  
  373. Revision *Revision::ConditionalSetRevision (Revision *rev, Revision *base)
  374. {
  375.     int        i, retval = 0;
  376.  
  377.     for (i = 0; i < ARRAY_SIZE; i++)
  378.     {
  379.     if (rev->number[i] != base->number[i])
  380.     {
  381.         if ((base->number[i] == -1) && (rev->number[i+1] == -1))
  382.         {
  383.         if ((number[0] == -1) || (number[i] < rev->number[i]))
  384.             retval = 1;
  385.         }
  386.         break;
  387.     }
  388.     }
  389.  
  390.     if (!retval && (rev->number[i] == -1) && (base->number[i] == -1))
  391.     retval = 1;
  392.  
  393.     return retval ? rev : this;
  394. }
  395.  
  396. /*------------------------------------------------------------------------
  397.  * Revision::printRev
  398.  *------------------------------------------------------------------------*/
  399.  
  400. void Revision::printRev (char *indent)
  401. {
  402.     int        i;
  403.  
  404.     cout << indent;
  405.     for (i = 0; (i < ARRAY_SIZE) && (number[i] != -1); i++)
  406.     {
  407.     cout << number[i];
  408.     if (number[i+1] != -1)
  409.         cout << '.';
  410.     }
  411. #ifdef DEBUG1
  412.     cout << "     Address:  " << hex << this;
  413. #endif
  414.     cout << endl;
  415. }
  416.  
  417. /*------------------------------------------------------------------------
  418.  * Revision::printAll
  419.  *------------------------------------------------------------------------*/
  420.  
  421. void Revision::printAll (char *indent)
  422. {
  423.     int        i;
  424.     char    *nextindent;
  425.  
  426.     cout << indent << "Revision:      ";
  427.     printRev ("");
  428.     if (author)
  429.     cout << indent << "Author:        " << author << endl;
  430.     if (state)
  431.     cout << indent << "State:         " << state << endl;
  432.     if (branches[0])
  433.     {
  434.     cout << indent << "Branches:" << endl;
  435.     nextindent = new char [strlen (indent) + 3];
  436.     strcpy (nextindent, indent);
  437.     strcat (nextindent, "  ");
  438.     for (i = 0; (i < MAX_BRANCHES) && branches[i]; i++)
  439.         branches[i]->printRev (nextindent);
  440.     delete [] nextindent;
  441.     }
  442.  
  443.     if (nextRev)
  444.     {
  445.     cout << indent << "Next Revision: ";
  446.     nextRev->printRev ("");
  447.     }
  448. }
  449.  
  450. /*========================================================================
  451.  * Symbol class
  452.  *========================================================================*/
  453.  
  454. class Symbol
  455. {
  456.   private:
  457.     char    *name_string;
  458.     Revision    *defined_rev;        /* Revision as specified in file */
  459.     Revision    *actual_rev;        /* Highest revision found so far */
  460.     Symbol    *next;
  461.  
  462.   public:
  463.     Symbol (Symbol &s);
  464.     Symbol (char *c = NULL);
  465.     ~Symbol ();
  466.  
  467.     void    SetName (char *name);
  468.     void    SetDefinedRev (Revision *r);
  469.     int        SetActualRev (Revision *r);
  470.  
  471.     void    addSymbol (Symbol *s);
  472.     void    RecursiveDelete (void) { if (next)
  473.                          next->RecursiveDelete ();
  474.                      delete next;
  475.                      next = NULL; }
  476.  
  477.     char*    GetName (void) { return name_string; }
  478.     Revision*    getDefinedRev (void) { return defined_rev; }
  479.     Revision*    getActualRev (void) { return actual_rev; }
  480.     Symbol*    GetNext (void) { return next; }
  481.     void    printAll (char *indent);
  482. };
  483.  
  484. /*------------------------------------------------------------------------
  485.  * Symbol::Symbol
  486.  *------------------------------------------------------------------------*/
  487.  
  488. Symbol::Symbol (char *c)
  489. {
  490.     if (c)
  491.     {
  492.     name_string = new char [sizeof (c) + 1];
  493.     strcpy (name_string, c);
  494.     }
  495.     else
  496.     name_string = NULL;
  497.     defined_rev = NULL;
  498.     actual_rev = NULL;
  499.     next = NULL;
  500. }
  501.  
  502. /*------------------------------------------------------------------------
  503.  * Symbol::Symbol
  504.  *------------------------------------------------------------------------*/
  505.  
  506. Symbol::Symbol (Symbol &s)
  507. {
  508.     name_string = new char[strlen (s.name_string) + 1];
  509.     strcpy (name_string, s.name_string);
  510.     defined_rev = s.defined_rev;
  511.     actual_rev = s.actual_rev;
  512.     next = s.next;
  513. }
  514.  
  515. /*------------------------------------------------------------------------
  516.  * Symbol::~Symbol
  517.  *------------------------------------------------------------------------*/
  518.  
  519. Symbol::~Symbol ()
  520. {
  521.     delete [] name_string;
  522. }
  523.  
  524. /*------------------------------------------------------------------------
  525.  * Symbol::SetName
  526.  *------------------------------------------------------------------------*/
  527.  
  528. void Symbol::SetName (char *name)
  529. {
  530.     name_string = new char [strlen (name) + 1];
  531.     strcpy (name_string, name);
  532. }
  533.  
  534. /*------------------------------------------------------------------------
  535.  * Symbol::SetDefinedRev
  536.  *------------------------------------------------------------------------*/
  537.  
  538. void Symbol::SetDefinedRev (Revision *rev)
  539. {
  540.     defined_rev = rev;
  541. }
  542.  
  543. /*------------------------------------------------------------------------
  544.  * Symbol::SetActualRev
  545.  *------------------------------------------------------------------------*/
  546.  
  547. int Symbol::SetActualRev (Revision *rev)
  548. {
  549.     Revision    *orig = actual_rev;
  550.     dType    returned_type;
  551.  
  552.     if (actual_rev)
  553.     {
  554.     actual_rev = actual_rev->ConditionalSetRevision (rev, defined_rev);
  555.     }
  556.     else
  557.     {
  558.     if (defined_rev)
  559.     {
  560.         returned_type = defined_rev->CompareRevs (*rev);
  561.         if ((returned_type == SAME) || (returned_type == MORE_LEVELS))
  562.         actual_rev = rev;
  563.     }
  564.     else
  565.         actual_rev = rev;
  566.     }
  567.  
  568.     return (orig != actual_rev);
  569. }
  570.  
  571. /*------------------------------------------------------------------------
  572.  * Symbol::addSymbol
  573.  *------------------------------------------------------------------------*/
  574.  
  575. void Symbol::addSymbol (Symbol *s)
  576. {
  577.     if (next)
  578.     next->addSymbol (s);
  579.     else
  580.     next = s;
  581. }
  582.  
  583. /*------------------------------------------------------------------------
  584.  * Symbol::printAll
  585.  *------------------------------------------------------------------------*/
  586.  
  587. void Symbol::printAll (char *indent)
  588. {
  589.     char    *nextindent;
  590.  
  591.     nextindent = new char [strlen (indent) + 5];
  592.     strcpy (nextindent, indent);
  593.     strcat (nextindent, "    ");
  594.  
  595.     if (name_string)
  596.     cout << indent << name_string;
  597. #ifdef DEBUG1
  598.     cout << "    Address:  " << hex << this;
  599. #endif
  600.     cout << endl;
  601.     if (defined_rev)
  602.     {
  603.     cout << indent << "Defined revision:" << endl;
  604.     defined_rev->printRev (nextindent);
  605.     }
  606.     if (actual_rev)
  607.     {
  608.     cout << indent << "Actual revision:" << endl;
  609.     actual_rev->printRev (nextindent);
  610.     }
  611.  
  612.     delete [] nextindent;
  613.     cout << endl;
  614.  
  615.     if (next)
  616.     next->printAll (indent);
  617. }
  618.  
  619. /*========================================================================
  620.  * RCSDelta class
  621.  *========================================================================*/
  622.  
  623. class RCSDelta : public Revision
  624. {
  625.   private:
  626.     RCSDelta    *next;
  627.  
  628.   public:
  629.     RCSDelta (char *c = NULL) 
  630.     : Revision (c) { next = NULL; }
  631.     RCSDelta (RCSDelta &r) 
  632.     : Revision (r) { next = NULL; }
  633. /*
  634.     RCSDelta& operator= (Revision &r) { ((Revision *)this) = r;
  635.                     next = NULL;
  636.                     return *this; }
  637. */
  638.     void    AddDelta (RCSDelta *d);
  639.     RCSDelta    *NextDelta (void) { return next; }
  640.     RCSDelta    *FindDelta (char *r);
  641.     RCSDelta    *FindDelta (Revision &rev);
  642.     RCSDelta    *FindBranch (char *r);
  643.     RCSDelta    *FindBranch (Revision &rev);
  644.     void    RecursiveDelete (void) { if (next)
  645.                          next->RecursiveDelete ();
  646.                      delete next;
  647.                      next = NULL; }
  648.     void    printAll (char *indent);
  649. };
  650.  
  651. /*------------------------------------------------------------------------
  652.  * RCSDelta::AddDelta
  653.  *------------------------------------------------------------------------*/
  654.  
  655. void RCSDelta::AddDelta (RCSDelta *d)
  656. {
  657.     if (next)
  658.     next->AddDelta (d);
  659.     else
  660.     next = d;
  661. }
  662.  
  663. /*------------------------------------------------------------------------
  664.  * RCSDelta::FindDelta
  665.  *------------------------------------------------------------------------*/
  666.  
  667. RCSDelta *RCSDelta::FindDelta (char *r)
  668. {
  669.     Revision        rev (r);
  670.     dType        t;
  671.  
  672.     t = CompareRevs (rev);
  673.     if (t == SAME)
  674.     return this;
  675.  
  676.     if (next)
  677.     return next->FindDelta (rev);
  678.  
  679.     return NULL;
  680. }
  681.  
  682. /*------------------------------------------------------------------------
  683.  * RCSDelta::FindDelta
  684.  *------------------------------------------------------------------------*/
  685.  
  686. RCSDelta *RCSDelta::FindDelta (Revision &rev)
  687. {
  688.     dType        t;
  689.  
  690.     t = CompareRevs (rev);
  691.     if (t == SAME)
  692.     return this;
  693.  
  694.     if (next)
  695.     return next->FindDelta (rev);
  696.  
  697.     return NULL;
  698. }
  699.  
  700. /*------------------------------------------------------------------------
  701.  * RCSDelta::FindBranch
  702.  *------------------------------------------------------------------------*/
  703.  
  704. RCSDelta *RCSDelta::FindBranch (char *r)
  705. {
  706.     Revision        rev (r);
  707.     dType        t;
  708.  
  709.     t = CompareRevs (rev);
  710.     if ((t == SAME) || (t == MORE_LEVELS))
  711.     return this;
  712.  
  713.     if (next)
  714.     return next->FindDelta (rev);
  715.  
  716.     return NULL;
  717. }
  718.  
  719. /*------------------------------------------------------------------------
  720.  * RCSDelta::FindBranch
  721.  *------------------------------------------------------------------------*/
  722.  
  723. RCSDelta *RCSDelta::FindBranch (Revision &rev)
  724. {
  725.     dType        t;
  726.  
  727.     t = CompareRevs (rev);
  728.     if ((t == SAME) || (t == MORE_LEVELS))
  729.     return this;
  730.  
  731.     if (next)
  732.     return next->FindDelta (rev);
  733.  
  734.     return NULL;
  735. }
  736.  
  737. /*------------------------------------------------------------------------
  738.  * RCSDelta::printAll
  739.  *------------------------------------------------------------------------*/
  740.  
  741. void RCSDelta::printAll (char *indent)
  742. {
  743.     Revision::printAll (indent);
  744.     cout << endl;
  745.  
  746.     if (next)
  747.     next->printAll (indent);
  748. }
  749.  
  750. /*========================================================================
  751.  * Locks class
  752.  *========================================================================*/
  753.  
  754. class Locks
  755. {
  756.   private:
  757.     char    *user;
  758.     RCSDelta    *rev;
  759.     int        strict;
  760.     Locks    *next;
  761.  
  762.   public:
  763.     Locks ();
  764.     Locks (char *u, RCSDelta *r);
  765.     ~Locks ();
  766.  
  767.     void addLock (Locks *l);
  768.     void RecursiveDelete (void) { if (next)
  769.                       next->RecursiveDelete ();
  770.                   delete next;
  771.                   next = NULL; }
  772.     void setStrict (int state);
  773.     void printAll (char *indent);
  774. };
  775.  
  776. /*------------------------------------------------------------------------
  777.  * Locks::Locks
  778.  *------------------------------------------------------------------------*/
  779.  
  780. Locks::Locks ()
  781. {
  782.     user = NULL;
  783.     rev = NULL;
  784.     strict = False;
  785.     next = NULL;
  786. }
  787.  
  788. /*------------------------------------------------------------------------
  789.  * Locks::Locks
  790.  *------------------------------------------------------------------------*/
  791.  
  792. Locks::Locks (char *u, RCSDelta *r)
  793. {
  794.     user = new char [strlen (u) + 1];
  795.     strcpy (user, u);
  796.     rev = r;
  797.     strict = False;
  798.     next = NULL;
  799. }
  800.  
  801. /*------------------------------------------------------------------------
  802.  * Locks::~Locks
  803.  *------------------------------------------------------------------------*/
  804.  
  805. Locks::~Locks ()
  806. {
  807.     if (user)
  808.     delete [] user;
  809.  
  810.     if (rev)
  811.     delete rev;
  812. }
  813.  
  814. /*------------------------------------------------------------------------
  815.  * Locks::addLock
  816.  *------------------------------------------------------------------------*/
  817.  
  818. void Locks::addLock (Locks *l)
  819. {
  820.     if (next)
  821.     next->addLock (l);
  822.     else
  823.     next = l;
  824. }
  825.  
  826. /*------------------------------------------------------------------------
  827.  * Locks::setStrict
  828.  *------------------------------------------------------------------------*/
  829.  
  830. void Locks::setStrict (int state)
  831. {
  832.     strict = state;
  833.     if (next)
  834.     next->setStrict (state);
  835. }
  836.  
  837. /*------------------------------------------------------------------------
  838.  * Locks::printAll
  839.  *------------------------------------------------------------------------*/
  840.  
  841. void Locks::printAll (char *indent)
  842. {
  843.     if (user)
  844.     cout << indent << "User:       " << user;
  845. #ifdef DEBUG1
  846.     cout << "    Address:  " << hex << this;
  847. #endif
  848.     cout << endl;
  849.     cout << indent << "Strict:     " << (strict ? "TRUE" : "FALSE") << endl;
  850.     if (rev)
  851.     {
  852.     cout << indent << "Revision:   ";
  853.     rev->printRev ("");
  854.     }
  855.     cout << endl;
  856.  
  857.     if (next)
  858.     next->printAll (indent);
  859. }
  860.  
  861. /*========================================================================
  862.  * RCSFile class
  863.  *========================================================================*/
  864.  
  865. class RCSFile
  866. {
  867.   private:
  868.     char    *name;
  869.     Revision    *head;
  870.     Revision    *branch;
  871.     char    *access;
  872.     Symbol    *symbols;
  873.     Locks    *locks;
  874.     char    *comment;
  875.     char    *expand;
  876.     RCSDelta    *deltas;
  877.  
  878.   public:
  879.     RCSFile (char *file = NULL) { name = file;
  880.                   head = NULL;
  881.                   branch = NULL;
  882.                   access = NULL;
  883.                   symbols = NULL;
  884.                   locks = NULL;
  885.                   comment = NULL;
  886.                   expand = NULL;
  887.                   deltas = NULL; }
  888.     ~RCSFile ();
  889.     void    setHead (char *h);
  890.     void    addSymbol (char *sym, char *rev = NULL);
  891.     void    addDelta (RCSDelta *r);
  892.     void    setBranch (char *b);
  893.     void    setAccess (char *c);
  894.     Locks*    addLock (char *l);
  895.     void    setComment (char *c);
  896.     void    setExpand (char *c);
  897.     RCSDelta*    FindDelta (char *c);
  898.     void    setStrict (int state);
  899.     void    printAll (void);
  900.     char*    getName (void) { return name; }
  901.     Symbol*    getSymbol (void) { return symbols; }
  902.     Revision*    getHead (void) { return head; }
  903.     void    updateSymbols (RCSDelta *r);
  904. };
  905.  
  906. /*------------------------------------------------------------------------
  907.  * RCSFile::~RCSFile
  908.  *------------------------------------------------------------------------*/
  909.  
  910. RCSFile::~RCSFile ()
  911. {
  912.     if (access)
  913.     delete access;
  914.     if (symbols)
  915.     {
  916.     symbols->RecursiveDelete ();
  917.     delete symbols;
  918.     }
  919.     if (locks)
  920.     {
  921.     locks->RecursiveDelete ();
  922.     delete locks;
  923.     }
  924.     if (comment)
  925.     delete comment;
  926.     if (deltas)
  927.     {
  928.     deltas->RecursiveDelete ();
  929.     delete deltas;
  930.     }
  931. }
  932.  
  933. /*------------------------------------------------------------------------
  934.  * RCSFile::setHead
  935.  *------------------------------------------------------------------------*/
  936.  
  937. void RCSFile::setHead (char *h)
  938. {
  939.     RCSDelta        *d;
  940.  
  941.     if (head)
  942.     {
  943.     d = deltas->FindDelta (h);
  944.     if (d)
  945.     {
  946.         if (head != d)
  947.         cerr << "RCSFile: Replacing head" << endl;
  948.     }
  949.     else
  950.     {
  951.         d = new RCSDelta (h);
  952.         addDelta (d);
  953.     }
  954.     }
  955.     else
  956.     {
  957.     d = NULL;
  958.     if (deltas)
  959.         d = deltas->FindDelta (h);
  960.  
  961.     if (d == NULL)
  962.     {
  963.         d = new RCSDelta (h);
  964.         addDelta (d);
  965.     }
  966.     }
  967.  
  968.     head = d;
  969. }
  970.  
  971. /*------------------------------------------------------------------------
  972.  * RCSFile::addDelta
  973.  *------------------------------------------------------------------------*/
  974.  
  975. void RCSFile::addDelta (RCSDelta *r)
  976. {
  977.     if (deltas)
  978.     deltas->AddDelta (r);
  979.     else
  980.     deltas = r;
  981.  
  982.     updateSymbols (r);
  983. }
  984.  
  985. /*------------------------------------------------------------------------
  986.  * RCSFile::updateSymbols
  987.  *------------------------------------------------------------------------*/
  988.  
  989. void RCSFile::updateSymbols (RCSDelta *r)
  990. {
  991.     Symbol*    csymbol;
  992.  
  993.     /*----
  994.      * Scan through the defined symbols and see if there are any
  995.      * that this revision matches.
  996.      *----*/
  997.  
  998.     for (csymbol = symbols; csymbol; csymbol = csymbol->GetNext ())
  999.     {
  1000.     csymbol->SetActualRev (r);
  1001.     }
  1002. }
  1003.  
  1004. /*------------------------------------------------------------------------
  1005.  * RCSFile::addSymbol
  1006.  *------------------------------------------------------------------------*/
  1007.  
  1008. void RCSFile::addSymbol (char *sym, char *rev)
  1009. {
  1010.     char    *s = sym;
  1011.     char    *r = rev;
  1012.     Symbol    *ns;
  1013.     RCSDelta    *nr = NULL;
  1014.  
  1015.     if (rev == NULL)
  1016.     {
  1017.     s = new char [strlen (sym) + 1];
  1018.     strcpy (s, sym);
  1019.     r = strchr (s, ':');
  1020.     if (r)
  1021.         *r++ = '\0';
  1022.     }
  1023.  
  1024.     if (r)
  1025.     nr = FindDelta (r);
  1026.     if (nr == NULL)
  1027.     {
  1028.     nr = new RCSDelta (r);
  1029.     addDelta (nr);
  1030.     }
  1031.  
  1032.     ns = new Symbol (s);
  1033.     ns->SetDefinedRev (nr);
  1034.     if (symbols)
  1035.     symbols->addSymbol (ns);
  1036.     else
  1037.     symbols = ns;
  1038.  
  1039.     if (s != sym)
  1040.     delete [] s;
  1041. }
  1042.  
  1043. /*------------------------------------------------------------------------
  1044.  * RCSFile::setBranch
  1045.  *------------------------------------------------------------------------*/
  1046.  
  1047. void RCSFile::setBranch (char *b)
  1048. {
  1049.     RCSDelta        *d;
  1050.  
  1051.     if (branch)
  1052.     {
  1053.     d = deltas->FindDelta (b);
  1054.     if (d)
  1055.     {
  1056.         if (branch != d)
  1057.         cerr << "RCSFile: Replacing branch" << endl;
  1058.     }
  1059.     else
  1060.     {
  1061.         d = new RCSDelta (b);
  1062.         addDelta (d);
  1063.     }
  1064.     }
  1065.     else
  1066.     {
  1067.     d = NULL;
  1068.     if (deltas)
  1069.         d = deltas->FindDelta (b);
  1070.  
  1071.     if (d == NULL)
  1072.     {
  1073.         d = new RCSDelta (b);
  1074.         addDelta (d);
  1075.     }
  1076.     }
  1077.  
  1078.     branch = d;
  1079. }
  1080.  
  1081. /*------------------------------------------------------------------------
  1082.  * RCSFile::setAccess
  1083.  *------------------------------------------------------------------------*/
  1084.  
  1085. void RCSFile::setAccess (char *c)
  1086. {
  1087.     if (access)
  1088.     delete [] access;
  1089.  
  1090.     access = new char [sizeof (c) + 1];
  1091.     strcpy (access, c);
  1092. }
  1093.  
  1094. /*------------------------------------------------------------------------
  1095.  * RCSFile::addLock
  1096.  *    l = string containing the following info:
  1097.  *        <user>:<delta>
  1098.  *    where:
  1099.  *        <user>    = User name.
  1100.  *        <delta>    = Delta user has checked out.
  1101.  *------------------------------------------------------------------------*/
  1102.  
  1103. Locks *RCSFile::addLock (char *l)
  1104. {
  1105.     char    *dstr, *user;
  1106.     Locks    *lock;
  1107.     RCSDelta    *d;
  1108.  
  1109.     dstr = strchr (l, ':');
  1110.     if (dstr == NULL)
  1111.     {
  1112.     dstr = l;
  1113.     user = new char [1];
  1114.     *user = '\0';
  1115.     }
  1116.     else
  1117.     {
  1118.     dstr++;
  1119.     user = new char [dstr - l];
  1120.     strncpy (user, l, dstr - l - 1);
  1121.     user[dstr-l-1] = '\0';
  1122.     }
  1123.  
  1124.     d = NULL;
  1125.     if (deltas)
  1126.     d = deltas->FindDelta (dstr);
  1127.  
  1128.     if (d == NULL)
  1129.     {
  1130.     d = new RCSDelta (dstr);
  1131.     deltas->AddDelta (d);
  1132.     }
  1133.  
  1134.     lock = new Locks (user, d);
  1135.     if (locks)
  1136.     locks->addLock (lock);
  1137.     else
  1138.     locks = lock;
  1139.  
  1140.     delete [] user;
  1141.     return lock;
  1142. }
  1143.  
  1144. /*------------------------------------------------------------------------
  1145.  * RCSFile::setComment
  1146.  *------------------------------------------------------------------------*/
  1147.  
  1148. void RCSFile::setComment (char *c)
  1149. {
  1150.     if (comment)
  1151.     delete [] comment;
  1152.  
  1153.     comment = new char [sizeof (c) + 1];
  1154.     strcpy (comment, c);
  1155. }
  1156.  
  1157. /*------------------------------------------------------------------------
  1158.  * RCSFile::setExpand
  1159.  *------------------------------------------------------------------------*/
  1160.  
  1161. void RCSFile::setExpand (char *c)
  1162. {
  1163.     if (expand)
  1164.     delete [] expand;
  1165.  
  1166.     expand = new char [sizeof (c) + 1];
  1167.     strcpy (expand, c);
  1168. }
  1169.  
  1170. /*------------------------------------------------------------------------
  1171.  * RCSFile::FindDelta
  1172.  *------------------------------------------------------------------------*/
  1173.  
  1174. RCSDelta *RCSFile::FindDelta (char *c)
  1175. {
  1176.     if (deltas)
  1177.     return deltas->FindDelta (c);
  1178.     return NULL;
  1179. }
  1180.  
  1181. /*------------------------------------------------------------------------
  1182.  * RCSFile::setStrict
  1183.  *------------------------------------------------------------------------*/
  1184.  
  1185. void RCSFile::setStrict (int state)
  1186. {
  1187.     if (locks)
  1188.     locks->setStrict (state);
  1189. }
  1190.  
  1191. /*------------------------------------------------------------------------
  1192.  * RCSFile::printAll
  1193.  *------------------------------------------------------------------------*/
  1194.  
  1195. void RCSFile::printAll (void)
  1196. {
  1197.     cout << "Name:         " << name << endl;
  1198.     if (head)
  1199.     {
  1200.     cout << "  Head:         ";
  1201.     head->printRev ("");
  1202.     }
  1203.     if (branch)
  1204.     {
  1205.     cout << "  Branches:" << endl;
  1206.     head->printRev ("    ");
  1207.     }
  1208.     if (access)
  1209.     cout << "  Access:       '" << access << "'" << endl;
  1210.     if (symbols)
  1211.     {
  1212.     cout << "  Symbols:" << endl;
  1213.     symbols->printAll ("    ");
  1214.     }
  1215.     if (locks)
  1216.     {
  1217.     cout << "  Locks:" << endl;
  1218.     locks->printAll ("    ");
  1219.     }
  1220.     if (comment)
  1221.     cout << "  Comment:      '" << comment << "'" << endl;
  1222.     if (expand)
  1223.     cout << "  Expand:        " << expand << endl;
  1224.     if (deltas)
  1225.     {
  1226.     cout << "  Deltas:" << endl;
  1227.     deltas->printAll ("    ");
  1228.     }
  1229.     cout << endl;
  1230. }
  1231.  
  1232. /*========================================================================
  1233.  * Main subroutines
  1234.  *========================================================================*/
  1235.  
  1236. static int    a_opt = 0, b_opt = 0, t_opt = 0;
  1237. static char    *symbol;
  1238. static char    *ProgName;
  1239. static char    linein[1024], lineout[132];
  1240. static char    data_1[1024];
  1241.  
  1242. /*------------------------------------------------------------------------
  1243.  * readFile
  1244.  *------------------------------------------------------------------------*/
  1245.  
  1246. RCSFile *readFile (char *filename)
  1247. {
  1248.     RCSFile        *rcsFile;
  1249.     char        *cptr, *dptr;
  1250.     RCSDelta        *aDelta, *bDelta;
  1251.     Locks        *lock;
  1252.  
  1253.     /*----
  1254.      * Open file and set fptr to the beginning of the root name.
  1255.      *----*/
  1256.     
  1257.     ifstream file (filename);
  1258.     if (!file)
  1259.     {
  1260.     cerr << ProgName << ": Problem opening file " << filename << endl;
  1261.     return NULL;
  1262.     }
  1263.     
  1264.     char *fptr = strrchr (filename, '/');
  1265.     int line_not_processed, quit;
  1266.     
  1267.     if (fptr)
  1268.     fptr++;
  1269.     else
  1270.     fptr = filename;
  1271.     
  1272.     rcsFile = new RCSFile (fptr);
  1273.     
  1274.     for (quit = 0; !file.eof () && !quit; )
  1275.     {
  1276.     file.getline (linein, sizeof (linein));
  1277.     if (strlen (linein) == 0)
  1278.         continue;
  1279.     
  1280.     cptr = linein;
  1281.     for (line_not_processed = 1; line_not_processed; )
  1282.     {
  1283.         SKIP_SPACE (cptr);
  1284.         
  1285.         /*----
  1286.          * HEAD
  1287.          *----*/
  1288.         
  1289.         if (strncmp (cptr, "head", 4) == 0)
  1290.         {
  1291.         cptr += 4;
  1292.         SKIP_SPACE (cptr);
  1293.         for (dptr = data_1; *dptr = *cptr; dptr++, cptr++)
  1294.             if (*cptr == ';')
  1295.             {
  1296.             *dptr = '\0';
  1297.             cptr++;
  1298.             break;
  1299.             }
  1300.         rcsFile->setHead (data_1);
  1301.         if (*cptr == '\0')
  1302.             line_not_processed = 0;
  1303.         }
  1304.         
  1305.         /*----
  1306.          * BRANCH
  1307.          *----*/
  1308.         
  1309.         else if (strncmp (cptr, "branch", 6) == 0)
  1310.         {
  1311.         cptr += 6;
  1312.         SKIP_SPACE (cptr);
  1313.         for (dptr = data_1; *dptr = *cptr; dptr++, cptr++)
  1314.             if (*cptr == ';')
  1315.             {
  1316.             *dptr = '\0';
  1317.             cptr++;
  1318.             break;
  1319.             }
  1320.         rcsFile->setBranch (data_1);
  1321.         if (*cptr == '\0')
  1322.             line_not_processed = 0;
  1323.         }
  1324.         
  1325.         /*----
  1326.          * ACCESS
  1327.          *----*/
  1328.         
  1329.         else if (strncmp (cptr, "access", 6) == 0)
  1330.         {
  1331.         cptr += 6;
  1332.         SKIP_SPACE (cptr);
  1333.         for (dptr = data_1; *dptr = *cptr; dptr++, cptr++)
  1334.             if (*cptr == ';')
  1335.             {
  1336.             *dptr = '\0';
  1337.             cptr++;
  1338.             break;
  1339.             }
  1340.         rcsFile->setAccess (data_1);
  1341.         if (*cptr == '\0')
  1342.             line_not_processed = 0;
  1343.         }
  1344.         
  1345.         /*----
  1346.          * SYMBOLS
  1347.          *----*/
  1348.         
  1349.         else if (strncmp (cptr, "symbols", 7) == 0)
  1350.         {
  1351.         cptr += 7;
  1352.         SKIP_SPACE (cptr);
  1353.         for (dptr = data_1; ((*dptr = *cptr++) != ';'); dptr++)
  1354.         {
  1355.             if (*dptr == '\0')
  1356.             {
  1357.             if (dptr != data_1)
  1358.                 rcsFile->addSymbol (data_1);
  1359.             file.getline (linein, sizeof (linein));
  1360.             cptr = linein;
  1361.             SKIP_SPACE (cptr);
  1362.             dptr = data_1 - 1;
  1363.             continue;
  1364.             }
  1365.             if (isspace (*dptr))
  1366.             {
  1367.             if (dptr != data_1)
  1368.             {
  1369.                 *dptr = '\0';
  1370.                 rcsFile->addSymbol (data_1);
  1371.                 dptr = data_1 - 1;
  1372.             }
  1373.             }
  1374.         }
  1375.         *dptr = '\0';
  1376.         if (dptr != data_1)
  1377.             rcsFile->addSymbol (data_1);
  1378.         if (*cptr == '\0')
  1379.             line_not_processed = 0;
  1380.         }
  1381.         
  1382.         /*----
  1383.          * LOCKS
  1384.          *----*/
  1385.         
  1386.         else if (strncmp (cptr, "locks", 5) == 0)
  1387.         {
  1388.         cptr += 5;
  1389.         SKIP_SPACE (cptr);
  1390.         for (dptr = data_1; ((*dptr = *cptr++) != ';'); dptr++)
  1391.         {
  1392.             if (*dptr == '\0')
  1393.             {
  1394.             if (dptr != data_1)
  1395.                 lock = rcsFile->addLock (data_1);
  1396.             file.getline (linein, sizeof (linein));
  1397.             cptr = linein;
  1398.             SKIP_SPACE (cptr);
  1399.             dptr = data_1 - 1;
  1400.             continue;
  1401.             }
  1402.             if (isspace (*dptr))
  1403.             {
  1404.             if (dptr != data_1)
  1405.             {
  1406.                 *dptr = '\0';
  1407.                 lock = rcsFile->addLock (data_1);
  1408.                 dptr = data_1 - 1;
  1409.             }
  1410.             }
  1411.         }
  1412.         *dptr = '\0';
  1413.         if (dptr != data_1)
  1414.             lock = rcsFile->addLock (data_1);
  1415.         
  1416.         if (*cptr != '\0')
  1417.         {
  1418.             SKIP_SPACE (cptr);
  1419.             if (strncmp (cptr, "strict", 6) == 0)
  1420.             {
  1421.             cptr += 6;
  1422.             rcsFile->setStrict (True);
  1423.             while (*cptr++ != ';');
  1424.             }
  1425.         }
  1426.         if (*cptr == '\0')
  1427.             line_not_processed = 0;
  1428.         }
  1429.         
  1430.         /*----
  1431.          * COMMENT
  1432.          *----*/
  1433.         
  1434.         else if (strncmp (cptr, "comment", 7) == 0)
  1435.         {
  1436.         cptr += 7;
  1437.         while (*cptr && (*cptr++ != '@'));
  1438.         
  1439.         for (dptr = data_1; 1; dptr++, cptr++)
  1440.         {
  1441.             while (*cptr == '\0')
  1442.             {
  1443.             if (file.eof ())
  1444.             {
  1445.                 *dptr = '\0';
  1446.                 break;
  1447.             }
  1448.             file.getline (linein, sizeof (linein));
  1449.             cptr = linein;
  1450.             *dptr++ = '\n';
  1451.             }
  1452.             if ((*dptr = *cptr) == '\0')
  1453.             break;
  1454.             if (*cptr == '@')
  1455.             {
  1456.             *dptr = '\0';
  1457.             break;
  1458.             }
  1459.         }
  1460.         while (*cptr && (*cptr++ != ';'));
  1461.         
  1462.         rcsFile->setComment (data_1);
  1463.         if (*cptr == '\0')
  1464.             line_not_processed = 0;
  1465.         }
  1466.         
  1467.         /*----
  1468.          * EXPAND
  1469.          *----*/
  1470.         
  1471.         else if (strncmp (cptr, "expand", 6) == 0)
  1472.         {
  1473.         cptr += 6;
  1474.         while (*cptr && (*cptr++ != '@'));
  1475.         
  1476.         for (dptr = data_1; 1; dptr++, cptr++)
  1477.         {
  1478.             while (*cptr = '\0')
  1479.             {
  1480.             if (file.eof ())
  1481.             {
  1482.                 *dptr = '\0';
  1483.                 break;
  1484.             }
  1485.             file.getline (linein, sizeof (linein));
  1486.             cptr = linein;
  1487.             *dptr++ = '\n';
  1488.             }
  1489.             if ((*dptr = *cptr) == '\0')
  1490.             break;
  1491.             if (*cptr == '@')
  1492.             {
  1493.             *dptr = '\0';
  1494.             break;
  1495.             }
  1496.             if (*cptr == ';')
  1497.             {
  1498.             *dptr = '\0';
  1499.             break;
  1500.             }
  1501.         }
  1502.         while (*cptr && (*cptr++ != ';'));
  1503.         
  1504.         rcsFile->setExpand (data_1);
  1505.         if (*cptr == '\0')
  1506.             line_not_processed = 0;
  1507.         }
  1508.         
  1509.         /*----
  1510.          * DESC
  1511.          *----*/
  1512.         
  1513.         else if (strncmp (cptr, "desc", 4) == 0)
  1514.         {
  1515.         cptr += 4;
  1516.         quit = 1;
  1517.         break;
  1518.         }
  1519.         
  1520.         /*----
  1521.          * Should be a revision
  1522.          *----*/
  1523.         
  1524.         else if (isdigit (*cptr))
  1525.         {
  1526.         for (dptr = cptr; *cptr && (*cptr != ';'); cptr++);
  1527.         *cptr = '\0';
  1528.         
  1529.         aDelta = rcsFile->FindDelta (dptr);
  1530.         if (aDelta == NULL)
  1531.         {
  1532.             aDelta = new RCSDelta (dptr);
  1533.             rcsFile->addDelta (aDelta);
  1534.         }
  1535.         rcsFile->updateSymbols (aDelta);
  1536.         
  1537.         while (!file.eof ())
  1538.         {
  1539.             file.getline (linein, sizeof (linein));
  1540.             if (strlen (linein) == 0)
  1541.             break;
  1542.             
  1543.             cptr = linein;
  1544.             for (line_not_processed = 1; line_not_processed; )
  1545.             {
  1546.             SKIP_SPACE (cptr);
  1547.             
  1548.             /*----
  1549.              * DATE
  1550.              *----*/
  1551.             
  1552.             if (strncmp (cptr, "date", 4) == 0)
  1553.             {
  1554.                 cptr += 4;
  1555.                 SKIP_SPACE (cptr);
  1556.                 for (dptr = cptr; *cptr && (*cptr != ';');
  1557.                  cptr++);
  1558.                 *cptr++ = '\0';
  1559.                 if (*cptr == '\0')
  1560.                 line_not_processed = 0;
  1561.             }
  1562.             
  1563.             /*----
  1564.              * AUTHOR
  1565.              *----*/
  1566.             
  1567.             else if (strncmp (cptr, "author", 6) == 0)
  1568.             {
  1569.                 cptr += 6;
  1570.                 SKIP_SPACE (cptr);
  1571.                 for (dptr = cptr; *cptr && (*cptr != ';');
  1572.                  cptr++);
  1573.                 *cptr++ = '\0';
  1574.                 aDelta->SetAuthor (dptr);
  1575.                 if (*cptr == '\0')
  1576.                 line_not_processed = 0;
  1577.             }
  1578.             
  1579.             /*----
  1580.              * STATE
  1581.              *----*/
  1582.             
  1583.             else if (strncmp (cptr, "state", 5) == 0)
  1584.             {
  1585.                 cptr += 5;
  1586.                 SKIP_SPACE (cptr);
  1587.                 for (dptr = cptr; *cptr && (*cptr != ';');
  1588.                  cptr++);
  1589.                 *cptr++ = '\0';
  1590.                 aDelta->SetState (dptr);
  1591.                 if (*cptr == '\0')
  1592.                 line_not_processed = 0;
  1593.             }
  1594.             
  1595.             /*----
  1596.              * BRANCHES
  1597.              *----*/
  1598.             
  1599.             else if (strncmp (cptr, "branches", 8) == 0)
  1600.             {
  1601.                 cptr += 8;
  1602.                 SKIP_SPACE (cptr);
  1603.                 for (dptr = data_1;
  1604.                  ((*dptr = *cptr++) != ';');
  1605.                  dptr++)
  1606.                 {
  1607.                 if (*dptr == '\0')
  1608.                 {
  1609.                     if (dptr != data_1)
  1610.                     {
  1611.                     bDelta =
  1612.                         rcsFile->FindDelta (data_1);
  1613.                     if (bDelta == NULL)
  1614.                     {
  1615.                         bDelta = new RCSDelta (data_1);
  1616.                         rcsFile->addDelta (bDelta);
  1617.                     }
  1618. //                    bDelta->AddBranch (bDelta);
  1619.                     }
  1620.                     file.getline (linein, sizeof (linein));
  1621.                     cptr = linein;
  1622.                     SKIP_SPACE (cptr);
  1623.                     dptr = data_1 - 1;
  1624.                 }
  1625.                 if (isspace (*dptr))
  1626.                 {
  1627.                     if (dptr != data_1)
  1628.                     {
  1629.                     *dptr = '\0';
  1630.                     bDelta =
  1631.                         rcsFile->FindDelta (data_1);
  1632.                     if (bDelta == NULL)
  1633.                     {
  1634.                         bDelta = new RCSDelta (data_1);
  1635.                         rcsFile->addDelta (bDelta);
  1636.                     }
  1637. //                    bDelta->AddBranch (bDelta);
  1638.                     }
  1639.                 }
  1640.                 }
  1641.                 *dptr = '\0';
  1642.                 if (dptr != data_1)
  1643.                 {
  1644.                 bDelta = rcsFile->FindDelta (data_1);
  1645.                 if (bDelta == NULL)
  1646.                 {
  1647.                     bDelta = new RCSDelta (data_1);
  1648.                     rcsFile->addDelta (bDelta);
  1649.                 }
  1650. //                bDelta->AddBranch (bDelta);
  1651.                 }
  1652.                 if (*cptr == '\0')
  1653.                 line_not_processed = 0;
  1654.             }
  1655.             
  1656.             /*----
  1657.              * NEXT
  1658.              *----*/
  1659.             
  1660.             else if (strncmp (cptr, "next", 4) == 0)
  1661.             {
  1662.                 cptr += 4;
  1663.                 SKIP_SPACE (cptr);
  1664.                 for (dptr = data_1; *dptr = *cptr++; dptr++)
  1665.                 if (*dptr == ';')
  1666.                 {
  1667.                     *dptr = '\0';
  1668.                     break;
  1669.                 }
  1670.                 if (strlen (data_1) > 0)
  1671.                 {
  1672.                 bDelta = rcsFile->FindDelta (data_1);
  1673.                 if (bDelta == NULL)
  1674.                 {
  1675.                     bDelta = new RCSDelta (data_1);
  1676.                     rcsFile->addDelta (bDelta);
  1677.                 }
  1678.                 aDelta->SetNext (bDelta);
  1679.                 }
  1680.                 if (*cptr == '\0')
  1681.                 line_not_processed = 0;
  1682.             }
  1683.             }
  1684.         }
  1685.         }
  1686.     }
  1687.     }
  1688.     file.close();
  1689.     
  1690.     return rcsFile;
  1691. }
  1692.  
  1693. /*========================================================================
  1694.  * MAIN ROUTINE
  1695.  *========================================================================*/
  1696.  
  1697. main (int argc, char *argv[])
  1698. {
  1699.     extern char        *optarg;
  1700.     extern int        optind, opterr, optopt;
  1701.     int            c;
  1702.     int            errflg = 0;
  1703.     struct stat        statbuf;
  1704.     char        **fileptr;
  1705.     RCSFile        *rcsFile;
  1706.     char        *cptr;
  1707.     Symbol        *csymbol;
  1708.     Revision        *rev;
  1709.  
  1710.     symbol = NULL;
  1711.  
  1712.     /*----
  1713.      * Figure out the program name without path.
  1714.      *----*/
  1715.     
  1716.     ProgName = strrchr (argv[0], '/');
  1717.     if (ProgName)
  1718.     ProgName++;
  1719.     else
  1720.     ProgName = argv[0];
  1721.     
  1722.     /*----
  1723.      * Collect options from command line.
  1724.      *----*/
  1725.     
  1726.     while ((c = getopt (argc, argv, "abts:")) != EOF)
  1727.     {
  1728.     switch (c) {
  1729.       case 'a':
  1730.         a_opt = 1;
  1731.         break;
  1732.         
  1733.       case 'b':
  1734.         b_opt = 1;
  1735.         break;
  1736.         
  1737.       case 't':
  1738.         t_opt = 1;
  1739.         break;
  1740.         
  1741.       case 's':
  1742.         symbol = optarg;
  1743.         break;
  1744.         
  1745.       case '?':
  1746.         errflg++;
  1747.     }
  1748.     }
  1749.     
  1750.     /*----
  1751.      * If an error occurred, print usage.
  1752.      *----*/
  1753.     
  1754.     if (errflg || optind >= argc)
  1755.     {
  1756.     cerr << "Usage: " << ProgName
  1757.          << " [-bl] [[-a] -s <symbol>] { <file-list> | <directory> }"
  1758.          << endl;
  1759.     cerr << "       -a    Print all files even if symbol not defined"
  1760.          << endl;
  1761.     cerr << "       -b    Print base revision number for each symbol"
  1762.          << endl;
  1763.     cerr << "       -t    Do not print title lines" << endl;
  1764.     return 0;
  1765.     }
  1766.     
  1767.     /*----
  1768.      * Find out if the first entry is a file or a directory.
  1769.      *----*/
  1770.     
  1771.     if (stat (argv[optind], &statbuf) != 0)
  1772.     {
  1773.     cerr << ProgName << ": Unable to get stat of " << argv[optind] << endl;
  1774.     cerr << strerror (errno) << endl;
  1775.     return 1;
  1776.     }
  1777.     
  1778.     if (S_ISDIR (statbuf.st_mode))
  1779.     {
  1780.     cerr << ProgName << ": Directories not yet supported." << endl;
  1781.     return -1;
  1782.     }
  1783.     else
  1784.     {
  1785.     fileptr = &argv[optind];
  1786.     }
  1787.     
  1788.     if (t_opt == 0)
  1789.     {
  1790.     cout << "File\t\t\tSymbol\t";
  1791.     if (b_opt)
  1792.         cout << "Base\t";
  1793.     cout << "Revision\tState" << endl;
  1794.     cout << "----\t\t\t------\t";
  1795.     if (b_opt)
  1796.         cout << "----\t";
  1797.     cout << "--------\t-----" << endl;
  1798.     }
  1799.  
  1800.     /*----
  1801.      * Now start looping through the files/directory.
  1802.      *----*/
  1803.     
  1804.     for ( ; *fileptr; fileptr++)
  1805.     {
  1806.     if (stat (*fileptr, &statbuf) != 0)
  1807.     {
  1808.         cerr << ProgName << ": Unable to get stat of " << *fileptr
  1809.          << endl;
  1810.         cerr << strerror (errno) << endl;
  1811.         continue;
  1812.     }
  1813.  
  1814.     if (S_ISDIR (statbuf.st_mode))
  1815.         continue;
  1816.  
  1817.     rcsFile = readFile (*fileptr);
  1818.     if (rcsFile == NULL)
  1819.         continue;
  1820.     
  1821. #ifdef DEBUG
  1822.     rcsFile->printAll ();
  1823. #endif
  1824.     
  1825.     cptr = rcsFile->getName ();
  1826.     c = strlen (cptr);
  1827.     strcpy (lineout, cptr);
  1828.  
  1829.     csymbol = rcsFile->getSymbol ();
  1830.  
  1831.     if (symbol == NULL)
  1832.     {
  1833.         cout << lineout;
  1834.         lineout[0] = '\0';
  1835.  
  1836.         rev = rcsFile->getHead ();
  1837.         if (rev)
  1838.         {
  1839.         TAB_OUT (c, 24);
  1840.         cout << "<Head>";
  1841.  
  1842.         TAB_OUT (c, 32+(8*b_opt));
  1843.         cptr = rev->GetRevision ();
  1844.         cout << cptr;
  1845.         c += strlen (cptr);
  1846.  
  1847.         TAB_OUT (c, 48+(8*b_opt));
  1848.         cptr = rev->GetState ();
  1849.         cout << cptr;
  1850.  
  1851.         cout << endl;
  1852.         c = 0;
  1853.         }
  1854.     }
  1855.  
  1856.     if (csymbol)
  1857.     {
  1858.         for ( ; csymbol; csymbol = csymbol->GetNext ())
  1859.         {
  1860.         if (symbol)
  1861.             if (strcmp (symbol, csymbol->GetName ()) != 0)
  1862.             continue;
  1863.  
  1864.         if (lineout[0])
  1865.         {
  1866.             cout << lineout;
  1867.             lineout[0] = '\0';
  1868.         }
  1869.  
  1870.         TAB_OUT (c, 24)
  1871.         cptr = csymbol->GetName ();
  1872.         cout << cptr;
  1873.         c += strlen (cptr);
  1874.  
  1875.         if (b_opt)
  1876.         {
  1877.             rev = csymbol->getDefinedRev ();
  1878.             if (rev)
  1879.             {
  1880.             TAB_OUT (c, 32);
  1881.             cptr = rev->GetRevision ();
  1882.             cout << cptr;
  1883.             c += strlen (cptr);
  1884.             }
  1885.         }
  1886.  
  1887.         rev = csymbol->getActualRev ();
  1888.         if (rev)
  1889.         {
  1890.             TAB_OUT (c, 32+(8*b_opt));
  1891.             cptr = rev->GetRevision ();
  1892.             cout << cptr;
  1893.             c += strlen (cptr);
  1894.  
  1895.             TAB_OUT (c, 48+(8*b_opt));
  1896.             cptr = rev->GetState ();
  1897.             cout << cptr;
  1898.         }
  1899.         cout << endl;
  1900.         c = 0;
  1901.         }
  1902.     }
  1903.  
  1904.     if (lineout[0] && a_opt)
  1905.     {
  1906.         cout << lineout;
  1907.         TAB_OUT (c, 24);
  1908.         cout << symbol;
  1909.         TAB_OUT (c, 32);
  1910.         cout << "<Undefined>" << endl;
  1911.     }
  1912.  
  1913.     delete rcsFile;
  1914.     }
  1915. }
  1916.